import requests
from bs4 import BeautifulSoup
import re, math

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36',
    'Host': 'search.51job.com',
    'Upgrade-Insecure-Requests': '1'}


def get_pagenumber(city_code, keyword):
    url = 'https://search.51job.com/list/' + str(city_code) + ',000000,0000,00,9,99,' + str(keyword) + ',2,1.html'
    r = requests.get(url, headers=headers)
    total = re.findall('\\"jobid\\_count\\"\\:\\"(\d+)', r.text)
    if total:
        pageNumber = math.ceil(int(total[0]) / 50)
        return pageNumber
    else:
        return 0
